package com.zzptc.lzh.myapp12;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.zzptc.lzh.myapp12.Adapter.PyqItemAdapter;
import com.zzptc.lzh.myapp12.Bean.PyqItem;

import org.litepal.LitePal;

import java.util.Collections;
import java.util.List;

public class PyqActivity extends AppCompatActivity {
    private ImageView postpyq,userimg;
    private TextView username;
    private ListView pyqlv;
    PyqItemAdapter adapter;
    List<PyqItem>pyqItemList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pyq);
        initView();
        setListener();
    }

    private void setListener() {
        postpyq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent it = new Intent(PyqActivity.this, PostActivity.class);
                startActivity(it);
                finish();
            }
        });
    }

    private void initView() {
        postpyq=findViewById(R.id.postpyq);
        pyqlv=findViewById(R.id.pyqlv);
        userimg=findViewById(R.id.userimg);
        username=findViewById(R.id.username);

        pyqItemList = LitePal.findAll(PyqItem.class);
        Collections.reverse(pyqItemList);
        adapter = new PyqItemAdapter(PyqActivity.this, R.layout.pyq_item,pyqItemList);
        pyqlv.setAdapter(adapter);


        SharedPreferences sp=getSharedPreferences("userinfo",MODE_PRIVATE);
        userimg.setImageResource(sp.getInt("myimg",-1));
        username.setText(sp.getString("myname",""));
    }
}
